#!/usr/bin/env python
# -*- coding: utf-8 -*-

from mm import *

class Mm_XML(Mm):
	def __init__(self, file):
		global xml
		xml = None
		
		import xml.sax.handler
		from xml.dom.minidom import parse
		
		conf = self.parse(file)
		
		self.set_status(conf[0])
		self.reader = None
		
	def read(self, *_file):
		if not _file:
			_file = self.get_status()
		else:
			_file = _file[0]
		
		doc = xml.dom.minidom.parse(open(_file))
		result = [[]]
		
		for person in doc.firstChild.childNodes:
			d = []
			for data in person.childNodes:
				
				if data.localName != None:
					d.append(data.firstChild.nodeValue)
						
					if not (data.localName in result[0]):
						result[0].append(data.localName)
				
			result.append(d)
			
		def f(x):
			if len(x) != 0:
				return x
			
		result = filter(f, result)
		self.data = result[1:]
		return result

#x = Mm_XML("adr.xml")
#print x.read()
#print x.data